<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    if (session.getAttribute("user") == null) {
        response.sendRedirect(request.getContextPath() + "/login.jsp");
        return;
    }

    com.company.ems.model.Employee employee =
            (com.company.ems.model.Employee) request.getAttribute("employee");

    if (employee == null) {
        response.sendRedirect("employees?action=list");
        return;
    }
%>
<html>
<head>
    <title>员工信息管理系统 - 查看员工</title>
    <link rel="stylesheet" href="../../css/style.css">
</head>
<body>
<header>
    <div class="logo">员工信息管理系统</div>
    <nav>
        <ul>
            <li><a href="../../dashboard">首页</a></li>
            <li><a href="employees?action=list" class="active">员工管理</a></li>
        </ul>
    </nav>
    <div class="user-info">
        <span>欢迎, <%= ((com.company.ems.model.User)session.getAttribute("user")).getUsername() %></span>
        <a href="../../logout" class="logout-btn">退出登录</a>
    </div>
</header>

<main>
    <div class="container">
        <div class="header-actions">
            <h2>员工详情</h2>
            <div>
                <a href="employees?action=edit&id=<%= employee.getId() %>" class="btn edit">编辑</a>
                <a href="employees?action=list" class="btn secondary">返回列表</a>
            </div>
        </div>

        <div class="detail-card">
            <div class="detail-row">
                <div class="detail-label">ID:</div>
                <div class="detail-value"><%= employee.getId() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">姓名:</div>
                <div class="detail-value"><%= employee.getName() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">部门:</div>
                <div class="detail-value"><%= employee.getDepartment() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">职位:</div>
                <div class="detail-value"><%= employee.getPosition() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">薪资:</div>
                <div class="detail-value"><%= employee.getSalary() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">邮箱:</div>
                <div class="detail-value"><%= employee.getEmail() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">电话:</div>
                <div class="detail-value"><%= employee.getPhone() %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">入职日期:</div>
                <div class="detail-value"><%= new java.text.SimpleDateFormat("yyyy-MM-dd").format(employee.getHireDate()) %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">创建时间:</div>
                <div class="detail-value"><%= new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(employee.getCreatedAt()) %></div>
            </div>

            <div class="detail-row">
                <div class="detail-label">最后更新时间:</div>
                <div class="detail-value"><%= new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(employee.getUpdatedAt()) %></div>
            </div>
        </div>
    </div>
</main>

<footer>
    <p>&copy; 2023 员工信息管理系统 版权所有</p>
</footer>
</body>
</html>